package luigibros.window;


import javax.swing.JFrame;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.Color;

/** Creates window and process KeyEvents
 * 
 * @author jackieberg7
 *
 */
public class Window extends JFrame implements KeyListener
{
	private volatile boolean back, forward, jump, crouch, accelerate, pause;
	
	/** Creates window
	 * 
	 */
	public Window()
	{
		this.setBackground(Color.BLUE);
		this.setSize(800, 500);
		addKeyListener(this);
	}
	
	/** Lets user see window
	 * 
	 * @param args
	 */
	public static void main(String[] args)
	{
		JFrame Window = new Window();
		Window.setVisible(true);
	}
	
	/** Does nothing
	 * 
	 */
	public void keyTyped(KeyEvent event)
	{
    }

	/** Get KeyEvents and set to true
	 * 
	 */
    public void keyPressed(KeyEvent event)
    {
		if(event.getKeyCode() == KeyEvent.VK_LEFT)
			back = true;
		else if(event.getKeyCode() == KeyEvent.VK_RIGHT)
			forward = true;
		else if(event.getKeyCode() == KeyEvent.VK_UP)
			jump = true;
		else if(event.getKeyCode() == KeyEvent.VK_DOWN)
			crouch = true;
		else if(event.getKeyCode() == KeyEvent.VK_SPACE)
			accelerate = true;
		else if(event.getKeyCode() == KeyEvent.VK_CONTROL)
			pause = true;
    }

    /** Get KeyEvents and set to false
     * 
     */
    public void keyReleased(KeyEvent event)
    {
		if(event.getKeyCode() == KeyEvent.VK_LEFT)
			back = false;
		else if(event.getKeyCode() == KeyEvent.VK_RIGHT)
			forward = false;
		else if(event.getKeyCode() == KeyEvent.VK_UP)
			jump = false;
		else if(event.getKeyCode() == KeyEvent.VK_DOWN)
			crouch = false;
		else if(event.getKeyCode() == KeyEvent.VK_SPACE)
			accelerate = false;
		else if(event.getKeyCode() == KeyEvent.VK_CONTROL)
			pause = false;
    }
}
